package com.nf.health.app.activity.my.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;


import com.nf.health.app.R;
import com.nf.health.app.activity.my.bean.RegisterBean;
import com.nf.health.app.adapter.OnMyClickListener;
import com.nf.health.app.utils.DateUtil;

import java.util.List;

/**
 * 个人中心 挂号
 * Created by Administrator on 2017/4/12.
 */
public class RegisterRecordAdapter extends BaseAdapter{

    private Context context;
    private List<RegisterBean> question;

    String a;
    public RegisterRecordAdapter(Context context, List<RegisterBean> question) {
        super();
        this.context = context;
        this.question = question;
    }
    @Override
    public int getCount() {
        if(question != null){
            return question.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return question.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null) {
            convertView = View.inflate(context, R.layout.item_register_record,null);
            holder = new ViewHolder();
            holder.record_date = (TextView) convertView.findViewById(R.id.record_date);
            holder.record_state = (TextView) convertView.findViewById(R.id.record_state);
            holder.record_time = (TextView) convertView.findViewById(R.id.record_time);
            holder.record_department = (TextView) convertView.findViewById(R.id.record_department);
            holder.record_doctor = (TextView) convertView.findViewById(R.id.record_doctor);
            holder.record_name = (TextView) convertView.findViewById(R.id.record_name);
            holder.record_phone = (TextView) convertView.findViewById(R.id.record_phone);
            holder.btn_record = (Button) convertView.findViewById(R.id.btn_record);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        RegisterBean reg = question.get(position);
        if(reg.getType().equals("1")){
            holder.record_state.setText("待确认");
            holder.btn_record.setText("取消预约");
        }else if(reg.getType().equals("2")){
            holder.record_state.setText("已预约");
            holder.btn_record.setText("评价");
        }else if(reg.getType().equals("3")){
            holder.record_state.setText("已取消");
            holder.btn_record.setText("再次挂号");
        }else if(reg.getType().equals("4")){
            holder.record_state.setText("已预约");
            holder.btn_record.setText("再次挂号");
        }

        String date = DateUtil.date2String(Long.parseLong(reg.getCreatetime()), "yyyy-MM-dd");
        holder.record_date.setText("日期:"+ date);
        holder.record_time.setText("就诊时间:"+reg.getRtime());
        holder.record_department.setText("就诊科室:"+reg.getDepartment());
        holder.record_doctor.setText("预约医生:"+reg.getDname());
        holder.record_name.setText("就诊人:"+reg.getName());
        holder.record_phone.setText("手机号:" + reg.getPhone());


        final ViewHolder finalHolder = holder;
        holder.btn_record.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null)
                    listener.onClick(position,finalHolder.btn_record.getText().toString());
            }
        });

        return convertView;

    }
    private OnMyClickListener listener;
    public void setOnMyClickListener(OnMyClickListener listener){
        this.listener = listener;
    }

    public class ViewHolder{
        TextView record_date;
        TextView record_state;
        TextView record_time;
        TextView record_department;
        TextView record_doctor;
        TextView record_name;
        TextView record_phone;
        Button btn_record;

    }
}
